package com.bj.dz.service.impl;

import com.bj.dz.entity.TrafficBridge;
import com.bj.dz.mapper.TrafficBridgeMapper;
import com.bj.dz.service.TrafficBridgeService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class TrafficBridgeServiceImpl implements TrafficBridgeService {

    @Resource
    private TrafficBridgeMapper trafficBridgeMapper;

    public TrafficBridge getTrafficBridgeById(Integer id){
        return trafficBridgeMapper.getTrafficBridgeById(id);
    }

    public List<TrafficBridge>	getTrafficBridgeListByMap(Map<String,Object> param){
        return trafficBridgeMapper.getTrafficBridgeListByMap(param);
    }

    public Integer getTrafficBridgeCountByMap(Map<String,Object> param){
        return trafficBridgeMapper.getTrafficBridgeCountByMap(param);
    }

    @Transactional
    public boolean addTrafficBridge(TrafficBridge trafficBridge){
            return trafficBridgeMapper.insertTrafficBridge(trafficBridge)>0?true:false;
    }

    @Transactional
    public boolean modifyTrafficBridge(TrafficBridge trafficBridge){
        return trafficBridgeMapper.updateTrafficBridge(trafficBridge)>0?true:false;
    }

    @Transactional
    public boolean deleteTrafficBridgeById(Integer id){
        return trafficBridgeMapper.deleteTrafficBridgeById(id)>0?true:false;
    }

    public Page<TrafficBridge> queryTrafficBridgePageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = trafficBridgeMapper.getTrafficBridgeCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<TrafficBridge> trafficBridgeList = trafficBridgeMapper.getTrafficBridgeListByMap(param);
        page.setRows(trafficBridgeList);
        return page;
    }

}
